
const pro_child_process = require('child_process');

const proProjects = require('./config/projectJson.json')
const areaName = process.argv[2];
const proArrObj = require('./config/areaBaseUrl.ts')[areaName]
let proArr = Object.keys(proArrObj); // 要打包的项目列表

let curJishu = 0;
const proNum = proArr.length;

console.log('项目列表', proArr, '数目' + proArr.length)
function proWorkerProcess(index) {
    const _process = pro_child_process.exec('yarn pro ' + proArr[index] + ' ' + areaName);
    console.log(`loading：正在打包${proArr[index]}`);
    _process.on('exit', function(code) {
        curJishu++
        if ((proNum - curJishu)) {
            console.log(`子进程${proArr[index]}已退出，退出码 ${code != 0 ? code + '，异常、异常' : '0,成功'}`);
            proWorkerProcess(curJishu)
        } else {
            console.log(`子进程${proArr[index]}已退出，退出码 ${code != 0 ? code + '，异常、异常' : '0,成功'}`);
            console.log('打包完成')
        }
    });
}
proWorkerProcess(0)